package com.tuling.code.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
/**
 * JDK Dynamic Proxy  (InvocationHandler)
 * @author lenovo
 *
 */
public class ProxyHandler implements InvocationHandler {
	
	private Person person;

	public ProxyHandler(Person person){
		this.person = person;
	}
	
	/**
	 * 具体需要代理的方法的实现
	 */
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		// TODO Auto-generated method stub
		
		before();
		method.invoke(person, args);
		after();
		return null;
	}

	/**
	 * 前置增强加入
	 */
	private void before(){
		System.out.println("This is the Before advice");
	}
	
	/**
	 * 后置增强加入
	 */
	private void after(){
		System.out.println("This is the After advice");
	}
}
